package com.bdqn.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import com.bdqn.dto.Dto;
import com.bdqn.mapper.CustomMapper;
import com.bdqn.model.CustomerBaseInfo;
import com.bdqn.service.CustomService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;


@Service("CustomService")
public class CustomServiceImpl implements CustomService {

	@Autowired
	private CustomMapper customMapper;

	@Override
	public List<CustomerBaseInfo> selectAll(String agent) {
		
		List<CustomerBaseInfo> custs = customMapper.selectAll(agent);
		
		return custs;
	}

	@Override
	public List<CustomerBaseInfo> selectLikeName(String companyName,String agent) {
		
		return customMapper.selectLikeName(companyName,agent);
	}

	@Override
	public PageInfo<CustomerBaseInfo> Search(String agent) {
		
		PageHelper.startPage(1, 8);
		
		List<CustomerBaseInfo> l = customMapper.selectAll(agent);
		
		PageInfo<CustomerBaseInfo> pageInfo = new PageInfo<CustomerBaseInfo>(l);
		
		pageInfo.setList(l);
		
		return pageInfo;
	}

	@Override
	public PageInfo<CustomerBaseInfo> likeSearch(String companyName, String agent) {

		PageHelper.startPage(1, 8);
		
		List<CustomerBaseInfo> l = customMapper.selectLikeName(companyName,agent);
		
		PageInfo<CustomerBaseInfo> pageInfo = new PageInfo<>(l);
		
		pageInfo.setList(l);
		return pageInfo;
	}

	@Override
	public boolean searchExist(String companyName, String agent) {

		int num = customMapper.searchExist(companyName,agent);
		
		if(num>0) {
			return true;
		}
		return false;
	}

	@Override
	public PageInfo<CustomerBaseInfo> page(Dto dto,String agent) {


		PageHelper.startPage(dto.getPageNum(),8);
		
		List<CustomerBaseInfo> l = customMapper.selectLikeName(dto.getWord(),agent);
		
		PageInfo<CustomerBaseInfo> pageInfo = new PageInfo<CustomerBaseInfo>(l);
		
		pageInfo.setList(l);
		
		return pageInfo;
	}

	@Override
	public CustomerBaseInfo check(Integer id) {
		return customMapper.check(id);
	}

	@Override
	public int alter(CustomerBaseInfo cust) {
		return customMapper.alter(cust);
	}

	@Override
	public int changeState(Integer id, String state) {
		return customMapper.changeState(id,state);
	}

	


	

	
	

	

	

	

}
